const { Random } = require('mockjs')
const Mock = require('mockjs')

const data = Mock.mock({
  'items|5': [{
    'id|+1': 0,//id int
    'name|+1': ['董事会', '人事部', '研发部', '行政部', '宣传部'],//部门名称 string
    code: '@string("upper", 5)',//部门编号 string
    positionIds: () => Random.pick(Mock.mock('@range(0,9)'), 2, 5),//职位列表 List<PositionId>
    state: '@integer(0,1)',//状态 int(0停用，1启用)
    manager: '@cname',//负责人 string
    'rememberCode|+1': ['DSH', 'RSB', 'YFB', 'XZB', 'XCB'],//助记码
  }]
})

module.exports = [
  {
    url: '/api/dep/list',
    type: 'get',
    response: config => {
      const items = data.items
      return {
        code: 20000,
        data: {
          total: items.length,
          items: items
        }
      }
    }
  },

  {
    url: '/api/dep/deleteById',
    type: 'get',
    response: config => {
      const { id } = config.query
      data.items = data.items.filter(dep => dep.id != id)
      return {
        code: 20000,
        message: "删除成功"
      }
    }
  },
]
